const { productService,UserInfo,User } = require('../../dbConfig/index.js')

const add = async (ctx,next) =>{
	const body = ctx.request.body
	const res = await productService.create({
		service_name:body.service_name,
		service_time:body.service_time,
		service_price:body.service_price,
		is_shop_vip:body.is_shop_vip,
		merchant_id:ctx.state.user_id,
		prod_img:body.prod_img
	})
		ctx.body = {code:200,date:null,msg:'新增服务成功'}
}
// 更新服务产品
const updateProduct = async (ctx,next) => {
	const body = ctx.request.body
	const res = await productService.update({
		service_name:body.service_name,
		service_time:body.service_time,
		service_price:body.service_price,
		is_shop_vip:body.is_shop_vip,
		prod_img:body.prod_img
	},{
		where:{Id:body.Id}
	})
		ctx.body = {code:200,date:null,msg:'修改成功'}
}
// 获取产品
const get = async (ctx,next) => {
	let res = null;
		res = await productService.findAll({
			where:{
				merchant_id:ctx.state.user_id
			}
		})
	ctx.body = {code:200,data:res,msg:'成功'}
}
const del = async (ctx,next) => {
	const body = ctx.request.body
	const res = await productService.destroy({
		where:{Id:body.Id}
	})
		ctx.body = {code:200,date:null,msg:'成功'}
}

module.exports = {
	add,
	updateProduct,
	get,
	del
}